package com.zhuliwei.controller;

import com.zhuliwei.constants.SystemConstants;
import com.zhuliwei.domain.ResponseResult;
import com.zhuliwei.domain.dto.AddCommentDto;
import com.zhuliwei.domain.entity.Comment;
import com.zhuliwei.service.CommentService;
import com.zhuliwei.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 评论接口控制层
 *
 * @author 朱力维
 * @time 2022/10/19 20:22
 **/
@RequestMapping("/comment")
@RestController
@Api(tags = "评论", description = "评论相关接口")
public class CommentController {
    @Resource
    private CommentService commentService;

    @GetMapping("/commentList")
    @ApiOperation(value = "文章评论列表", notes = "获取一页指定id的文章的评论")
    public ResponseResult commentList(String articleId, Integer pageNum, Integer pageSize) {
        return commentService.commentList(SystemConstants.ARTICLE_COMMENT, articleId, pageNum, pageSize);
    }

    @GetMapping("/linkCommentList")
    @ApiOperation(value = "友链评论列表", notes = "获取一页友链")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小")
    }
    )
    public ResponseResult commentList(Integer pageNum, Integer pageSize) {
        return commentService.commentList(SystemConstants.LINK_COMMENT, null, pageNum, pageSize);
    }

    @PostMapping
    @ApiOperation(value = "添加评论", notes = "添加评论接口，可以发表在文章也可以发表在友链")
    public ResponseResult addComment(@RequestBody AddCommentDto addCommentDto) {
        Comment comment = BeanCopyUtils.copyBean(addCommentDto, Comment.class);
        return commentService.addComment(comment);
    }

    @DeleteMapping("/{id}")
    public ResponseResult del(@PathVariable String id){
        commentService.removeById(id);
        return ResponseResult.okResult();
    }
}
